package com.huanying.goodjob.prize_chance;

import java.util.HashMap;
import java.util.Map;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.huanying.framework.BaseController;
import com.huanying.framework.PageBean;


@Controller
public class Prize_chanceController extends BaseController{
	@Autowired
	private Prize_chanceService prize_chanceService;
	private static Logger logger = Logger.getLogger(Prize_chanceController.class);
	//查询抽奖机会
	@RequestMapping("/show_add_prize_chance.do")
	public String show_add_prize_chance(String name,String chance_status,String page_num,Model model){
		
		
		Map<String,Object> map=new HashMap<String,Object>();
		PageBean pageBean = null;
		map.put("name", name);
		map.put("chance_status",chance_status);
		if(page_num==null)
		{
			page_num="1";
		}
		try {
			pageBean = prize_chanceService.search_prize_chance(map, super.getPageSize(), Integer.valueOf(page_num));
		} catch (NumberFormatException e) {
			logger.error("查询抽奖机会失败", e);
			// TODO Auto-generated catch block
		} catch (Exception e) {
			logger.error("查询抽奖机会失败", e);
			// TODO Auto-generated catch block
		}
		model.addAttribute("name",name);
		model.addAttribute("chance_status",chance_status);
		model.addAttribute("prize_chances",pageBean.getList());
		model.addAttribute("page",pageBean);
		return "/prize_chance/add_prize_chance";
	}
	//删除抽奖机会
	@RequestMapping("/delete_prize_chance.do")
	@ResponseBody
	public Map<String,Object> delete_prize_chance(String id){
		Map<String,Object> map=new HashMap<String,Object>();
		try {
			prize_chanceService.delete_prize_chance(Integer.parseInt(id));
			map.put("flag", "1");
		} catch (NumberFormatException e) {
			// TODO Auto-generated catch block
			logger.error("删除抽奖机会记录失败", e);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			logger.error("删除抽奖机会记录失败", e);
		}
		return map;
	}
	//更新抽奖机会
	@RequestMapping("/update_prize_chancestatus.do")
	@ResponseBody
	public Map<String,Object> update_prize_chancestatus(String id,String chance_status,String status)
	{
		Map<String,Object> map=new HashMap<String,Object>();
	    try {
			prize_chanceService.update_prize_chancestatus(Integer.parseInt(id),Integer.parseInt(status));
			prize_chanceService.update_prize_tatus(Integer.parseInt(id),Integer.parseInt(chance_status));
			///////////用户姓名
			map.put("flag", "1");
		    map.put("id",Integer.parseInt(id));
		    map.put("chance_status", chance_status);
	    } catch (NumberFormatException e) {
			// TODO Auto-generated catch block
			logger.error("修改抽奖机会记录状态失败", e);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			logger.error("修改抽奖机会记录状态失败", e);
		}
	   return map;
	}
	//获得单个抽奖机会
	@RequestMapping("/get_prize_chance.do")
	@ResponseBody
	public Map<String,Object> get_prize_chance(String id)
	{
		Map<String,Object> map=new HashMap<String,Object>();
		Prize_chance prize_chance;
		try {
			prize_chance=prize_chanceService.get_prize_chance(Integer.parseInt(id));
			map.put("prize_chance", prize_chance);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			logger.error("获取单个抽奖机会记录失败", e);
		}
		return map;
	}

}
